package cn.tedu.mall.search.service.impl;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.pojo.search.entity.SpuEntity;
import cn.tedu.mall.search.repository.SpuEntityRepository;
import cn.tedu.mall.search.service.ISearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
//实现查询远程服务器()ELK系统的信息的业务逻辑层
@Service
@Slf4j
public class SearchRemoteServiceImpl implements ISearchService {
    @Autowired
    private SpuEntityRepository spuEntityRepository;
    @Override
    public JsonPage<SpuEntity> search(String keyword, Integer page, Integer pageSize) {
        Page<SpuEntity> spus = spuEntityRepository.querySearchByText(keyword, PageRequest.of(page-1,pageSize));
        JsonPage<SpuEntity> jsonPage = new JsonPage<>();
        jsonPage.setPage(page);
        jsonPage.setPageSize(pageSize);
        jsonPage.setTotal(spus.getTotalElements());
        jsonPage.setTotalPage(spus.getTotalPages());
        jsonPage.setList(spus.getContent());
        return jsonPage;
    }

    @Override
    public void loadSpuByPage() {

    }










}
